package com.btex.app.treaty;

import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.btex.app.R;
import com.btex.app.entity.FuturesListInfo;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/10/19
 * @time 下午8:26
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class PopTreatyAdapter extends BaseQuickAdapter<FuturesListInfo.DataBean, BaseViewHolder> {
    private String mTrim;


    public PopTreatyAdapter(String trim) {
        super(R.layout.pop_item_adapter_treaty);
        mTrim = trim;
    }

    @Override
    protected void convert(BaseViewHolder helper, FuturesListInfo.DataBean item) {

        String settle_anchor = item.getSettle_anchor();


//        pop_item_treaty_lin_b
        String price_float_num = item.getPrice_float_num();

        Log.i("weikehwfihefiuwe", price_float_num);

        helper.addOnClickListener(R.id.pop_item_treaty_lin_b);

        TextView pop_treaty_item_tv_name = (TextView) helper.getView(R.id.pop_treaty_item_tv_name);
        TextView pop_treaty_item_tv_price = (TextView) helper.getView(R.id.pop_treaty_item_tv_price);
        TextView pop_treaty_item_tv_jiesuan = (TextView) helper.getView(R.id.pop_treaty_item_tv_jiesuan);
        TextView pop_treaty_item_tv_number = (TextView) helper.getView(R.id.pop_treaty_item_tv_number);
        LinearLayout pop_item_treaty_lin_b = (LinearLayout) helper.getView(R.id.pop_item_treaty_lin_b);

        pop_treaty_item_tv_jiesuan.setText("(" + settle_anchor + "结算" + ")");

        pop_treaty_item_tv_name.setText(item.getPair() + "永续");
        String contract_id = item.getContract_id();

        if (contract_id.equals(mTrim)) {
            pop_item_treaty_lin_b.setBackgroundResource(R.color.gray_bg);
        } else {
            pop_item_treaty_lin_b.setBackgroundResource(R.drawable.selector_item_gray);
        }
        String trade_price = item.getTicker().getTrade_price();
        if (!TextUtils.isEmpty(price_float_num) && !TextUtils.isEmpty(trade_price)) {
            String trim1 = Tools.round(Double.valueOf(trade_price), Integer.valueOf(price_float_num)).toString().trim();
            pop_treaty_item_tv_price.setText(trim1);
        }


        String change_24h = item.getTicker().getChange_24h();
        if (!TextUtils.isEmpty(change_24h)) {
            double v = Double.parseDouble(change_24h);
            if (v == 0 || v > 0) {
                pop_treaty_item_tv_number.setTextColor(Color.parseColor("#78aa21"));
                double v1 = Double.valueOf(item.getTicker().getChange_24h()) * 100;
                String trim = Tools.round(v1, 2).toString().trim();
                pop_treaty_item_tv_number.setText("+" + trim + "%");

            } else {
                pop_treaty_item_tv_number.setTextColor(Color.parseColor("#c91829"));
                double v1 = Double.valueOf(item.getTicker().getChange_24h()) * 100;
                String trim = Tools.round(v1, 2).toString().trim();
                pop_treaty_item_tv_number.setText(trim + "%");
            }
        }


    }

}
